/**
 *
 * <p>Title: PlaytimeRecTableRenderer.java</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004 Sun Microsystems, Inc.</p>
 * <p>Company: Sun Microsystems, Inc</p>
 * @author Jeff Kesselman
 * @version 1.0
 */
package com.worldwizards;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

/**
 *
 * <p>Title: PlaytimeRecTableRenderer.java</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004 Sun Microsystems, Inc.</p>
 * <p>Company: Sun Microsystems, Inc</p>
 * @author Jeff Kesselman
 * @version 1.0
 */
public class PlaytimeRecTableRenderer implements TableCellRenderer {
    private JLabel l = new JLabel();
    /* (non-Javadoc)
     * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
     */
    
    public PlaytimeRecTableRenderer(){
        //do nada        
    }
    
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
        
        l.setText(value.toString());
        l.setBackground(Color.WHITE);//default
        l.setOpaque(true);
        if (isSelected&&hasFocus){
            l.setBackground(Color.gray);
        } else if (column == 0){
            PlaytimeRecTableModel mdl = (PlaytimeRecTableModel) table.getModel();
            HeroPlaytimeRecord rec = mdl.getHeroPlaytimeRecord(row);
            if (rec.isDead()){
                l.setBackground(Color.RED);                
            } else if (rec.isUnconcious()){
                l.setBackground(Color.YELLOW);
            } else if (rec.isStunned()){
                l.setBackground(Color.gray);
            }
        } 
        return l;
    }

}
